<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//主页控制器
class IndexController extends Controller{

	//构造函数
	public function __init()
	{
	}
	
    //动作
    public function index(){
        //获取顶级分类数据
        $cate=new \Common\Model\Cate;
        $topCate=$cate->where("pid=0")->orderBy('sort','DESC')->get();
        // P($topCate);
        foreach($topCate as $k=>$v){
            $topCate[$k]['son']=$cate->where("pid={$v['cid']}")->get();
            foreach($topCate[$k]['son'] as $kk=>$vv){
                $topCate[$k]['son'][$kk]['sson']=$cate->where("pid={$vv['cid']}")->get();
            }
        }
        //获取最新添加的商品并截取前10条
        $goods=new \Common\Model\Goods;
        $newsData=$goods->orderBy('upload_time','DESC')->limit(10)->get();
        //获取手机配件顶级分类中的所有商品数据
        
        View::with('topCate',$topCate);
        View::with('newsData',$newsData);
        View::make();
    }

    // public function edl(){
    // 	$arr=Q("post.");
    // 	echo json_encode($arr);
    // }


}
